package com.project.lx.baseproject.widget;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;

import com.project.lx.baseproject.util.AppNetWorkMgr;
import com.project.lx.baseproject.util.LogUtils;
import com.project.lx.baseproject.util.ToastUtils;

/**
 * @author: X_Meteor
 * @description: 类描述
 * @version: V_1.0.0
 * @date: 2017/8/21 22:22
 * @company:
 * @email: lx802315@163.com
 */
public class NetworkChangeReceiver extends BroadcastReceiver {

    private static IntentFilter intentFilter;

    private static NetworkChangeReceiver mNetworkChangeReceiver = null;

    private NetworkChangeReceiver() {
    }

    public static NetworkChangeReceiver getInstance() {
        synchronized (NetworkChangeReceiver.class) {
            if (mNetworkChangeReceiver == null) {
                mNetworkChangeReceiver = new NetworkChangeReceiver();
            }
        }
        return mNetworkChangeReceiver;
    }

    /**
     * @return
     */
    public static IntentFilter getIntentFilter() {
        intentFilter = new IntentFilter();
        return intentFilter;
    }

    public static IntentFilter addAction(String Action) {
        if (intentFilter != null) {
            intentFilter.addAction(Action);
        } else {
            intentFilter = new IntentFilter();
            intentFilter.addAction(Action);
        }
        return intentFilter;
    }

    public static IntentFilter addCategory(String Category) {
        if (intentFilter != null) {
            intentFilter.addCategory(Category);
        } else {
            intentFilter = new IntentFilter();
            intentFilter.addCategory(Category);
        }
        return intentFilter;
    }

    @Override
    public void onReceive(Context context, Intent intent) {
        if (AppNetWorkMgr.isNetworkConnected(context)) {
            LogUtils.print("当前已经联网");
        }
    }


}
